package alkaid.eis.sys.service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

import alkaid.eis.sys.entity.Area;
import alkaid.eis.sys.entity.AreaType;
import lombok.experimental.UtilityClass;

/**
 * 地区查询条件
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
@UtilityClass
public class AreaSpecifications {
    public Specification<Area> empty() {
        return (Root<Area> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return null;
        };
    }

    public Specification<Area> typeEqual(AreaType type) {
        return (Root<Area> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.equal(root.get("type"), type);
        };
    }

    public Specification<Area> nameLike(String name) {
        return (Root<Area> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.like(root.get("name"), "%" + name + "%");
        };
    }

    public Specification<Area> codeLike(String code) {
        return (Root<Area> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.like(root.get("code"), "%" + code + "%");
        };
    }
}
